import axios from 'axios'
import { showToast } from 'vant'

const request = axios.create({
  baseURL: 'https://geek.itheima.net/',
})

request.interceptors.request.use(
  config => {
    try {
      const user = jk.getToken()
      console.log(user)
      if (user) {
        config.headers.Authorization = `Bearer ${user}`
      }
    } catch (error) {
      showToast({ message: (error as Error).toString() })
    }
    return config
  },
  err => {
    Promise.reject(err)
  },
)

export { request }
